<html>
  <head>
    <meta charset="utf8" />
    <title>Ajout d'un joueur</title>
	<link rel="stylesheet" href="style.css" />
  </head>
  <body>
<?php include("connexion-db.php");
include("retour-index.php"); ?>
<?php
$query_id_club = 'select ID_CLUB from CLUB where CLUB.NOM_CLUB="'.$_POST['club'].'"';
$res_id_club = $db->query($query_id_club);
$data_id_club = $res_id_club->fetch();

$query_personne = 'insert into PERSONNE
VALUES (NULL,"'.$_POST['nom'].'","'.$_POST['prenom'].'","'.$_POST['date-entree'].'","'.$data_id_club['ID_CLUB'].'")';
$res_personne = $db->query($query_personne);

$query_id_equipe = 'SELECT ID_EQUIPE
from EQUIPE E, CATEGORIE CA, CLUB C
where E.NOM_EQUIPE="'.$_POST['equipe'].'"
and CA.NOM_CATEGORIE="'.$_POST['categorie'].'"
and C.NOM_CLUB="'.$_POST['club'].'"
and E.ID_CAT=CA.ID_CAT
and CA.ID_CLUB=C.ID_CLUB';
$res_id_equipe = $db->query($query_id_equipe);
$data_id_equipe = $res_id_equipe->fetch();

$query_num_licence = 'select max(NUMERO_LICENCE)
from PERSONNE';
$res_num_licence = $db->query($query_num_licence);
$data_num_licence = $res_num_licence->fetch();

$query_joueur = 'insert into JOUEUR
VALUES ("'.$data_num_licence['max(NUMERO_LICENCE)'].'","'.$_POST['date-naissance'].'","'.$_POST['adresse'].'","'.$data_id_equipe['ID_EQUIPE'].'")';
$res_joueur = $db->query($query_joueur);
?>
<p>
Le joueur <?php echo $_POST['prenom'].' '.$_POST['nom']; ?> a bien été ajouté à la base de données.
</p>
  </body>
</html>
